<template>
  <div>
    <leftMain></leftMain>
      <transition :name='transitionName' >
      <div id="main">
        <div class='bg'>
          <h1 class='article-title'>{{data.title}}</h1>
          <div class='article-tips' >
            <i class='fa  fa-leaf yezi'></i>
            <a href="javascript:void(0)" v-for='(i,index) in tips.tips' :key='i' class='tips' :style='tips.color[index]' @click="allArticle('Tips-article-' + i)">
              {{i}}
            </a>
          </div>
          <span class='date fa fa-calendar'>{{data.date|FormatDate}}</span>
          <div class='details' v-html='compiledMarkdown'></div>
        </div>
        <div>
          <span class='copyright'>{{copyright}}</span>
        </div>
      </div>
    </transition>
  </div>
</template>
<script>
import leftMain from '@/components/leftmain'
import dbconf from '@/conf/db.conf'
import {highlightAll} from '@/unit/prism'
import {FormatDate} from '@/unit/fmt'
// import 'vue2-animate/dist/vue2-animate.min.css'
export default {
  name: 'Details',
  data () {
    return {
      data: {},
      a: false,
      transitionName: 'bounceRight'
    }
  },
  async mounted () {
    document.title = this.$route.params.k
    let Aid = this.$route.params.id
    await this.ajax.get(dbconf.url + 'queryDetailById?id=' + Aid).then(res => {
      this.data = res.data[0]
    }, err => {
      console.log(err)
    })
  },
  computed: {
    tips () {
      if (this.data.aid === undefined) {
        return ''
      }
      let tips = this.data.tips.split(',')
      let color = this.data.color.split(',')
      return {tips, color}
    },
    compiledMarkdown: function () {
      // if (this.data.conetnt) return ''
      return this.marked(this.data.content || '', { sanitize: true })
    },
    copyright () {
      return '©  ' + new Date().getFullYear() + '  华洛'
    }
  },
  components: {
    leftMain
  },
  updated () {
    highlightAll()
  },
  methods: {
    allArticle (arg) {
      this.$router.push('/index')
      this.$store.dispatch('setRigthPage', arg)
    }
  },
  filters: {
    FormatDate
  }
}
</script>
<style scoped>
#main {
  position: absolute;
  right: 0;
  min-height: 100%;
  background: #eaeaea;
  left: 25rem;
  width: auto;
  padding: 2.5rem 2rem;
}
.bg {
  background: #fff;
  padding-left: 3rem;
}
.article-title {
  margin: 0;
  /* padding-left: 3rem; */
  padding-top: 2rem;
  color: #7b5d5f;
}
.details {
  background: #fff;
  font-size: 1.3rem;
  padding-right: 2rem;
  padding-bottom: 2rem;
}
.article-tips {
    padding: 1.5rem 0 2rem;
    margin-top: 1rem;
    /* margin-left: 3rem; */
    margin-right: 2rem;
    border-bottom: 1px dashed #666;
}
.article-tips .detail {
    float: right;
    background: #4d4d4d;
    color: #fff;
    font-size: 12px;
    padding: 2px 8px 4px;
    line-height: 16px;
    -webkit-border-radius: 2px;
    -moz-border-radius: 2px;
    -webkit-border-radius: 2px;
    border-radius: 2px;
    -webkit-transition: background 0.3s;
    -moz-transition: background 0.3s;
    -ms-transition: background 0.3s;
    transition: background 0.3s;
    margin-top: -6px;
}
.article-tips .tips:before {
    content: " ";
    width: 0px;
    height: 0px;
    position: absolute;
    top: 0;
    left: -10px;
    border: 9px solid #fff;
    border-right-color: transparent;
}
.article-tips .tips:after {
    content: " ";
    width: 4px;
    height: 4px;
    background-color: #fff;
    -webkit-border-radius: 4px;
    border-radius: 4px;
    -webkit-box-shadow: 0px 0px 0px 1px rgba(0,0,0,0.3);
    box-shadow: 0px 0px 0px 1px rgba(0,0,0,0.3);
    position: absolute;
    top: 7px;
    left: 10px;
}
.article-tips .tips {
    display: inline-block;
    text-decoration: none;
    font-weight: normal;
    font-size: 12px;
    color: #fff;
    height: 18px;
    line-height: 18px;
    background: #ddd;
    float: left;
    padding: 0 5px 0px 20px;
    position: relative;
    left: 5px;
    -webkit-border-radius: 0 5px 5px 0;
    border-radius: 0 5px 5px 0;
    margin: 5px 9px 5px 8px;
    font-family: monaco, menlo, consolas, 'courier new', courier, monospace;
    margin-top: -6px;
}
.yezi {
    float: left;
    z-index: 999999;
    margin-top: -6px;
    position: relative;
}
.fa-leaf {
    color: #adaaaa;
    font-weight: 100;
    margin-right: -8px;
    font-size: 18px;
}
.date {
    position: absolute;
    right: 4rem;
    top: 9rem;
    color: #aaa;
    font-size: 1.2rem;
    font-weight: bold;
}
.fa-calendar {
    color: #666;
    font-weight: 100;
}
.copyright {
  margin-top: 3rem;
  display: block;
  color: #615c5c;
}
@media screen and (max-width: 800px) {
  #main {
    position: static;
    min-height: 100%;
    background: #eaeaea;
    padding: 2rem 0;
  }
  .article-tips .tips,
  .article-tips i {
    display: none;
  }
  .article-tips {
    padding: 0;
  }
  .bg {
    padding-left: 1.5rem;
  }
  .details {
    padding-right: 1rem;
  }
  .copyright {
    text-align: center;
  }
}
</style>
